/*
 * Copyright (c) 2009, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "sys/queue.h"
#include "tssp.h"
#include "tssp_table.h"

#ifndef _TSSP_PMT_H_
#define _TSSP_PMT_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

struct tssp_pmt_es {
    uint8_t type;   /**< stream_type */
    uint16_t pid;   /**< elementary_PID */

    struct tssp_descriptors descriptors;

    STAILQ_ENTRY(tssp_pmt_es) entry;
};

STAILQ_HEAD(tssp_pmt_es_list, tssp_pmt_es);

struct tssp_pmt {
    uint16_t program_number;    /**< program_number */
    uint8_t version;            /**< version_number */
    uint8_t current_next;       /**< current_next_indicator */

    uint16_t pcr_pid;           /**< PCR_PID */

    struct tssp_descriptors descriptors;
    struct tssp_pmt_es_list es_list;
};

struct tssp_pmt_monitor;

typedef void (*tssp_pmt_monitor_callback)(struct tssp_pmt_monitor *monitor,
                                          struct tssp_pmt *pmt,
                                          struct tssp_section *section,
                                          void *userdata);

struct tssp_pmt *tssp_pmt_parse(const struct tssp_section *section);
struct tssp_pmt *tssp_pmt_create(uint16_t program_number,
                                 uint8_t version,
                                 uint8_t current_next,
                                 uint16_t pcr_pid);
struct tssp_pmt_es *tssp_pmt_add_es(struct tssp_pmt *pmt,
                                    uint8_t type,
                                    uint16_t pid);
void tssp_pmt_destroy(struct tssp_pmt *pmt);
void tssp_pmt_es_destroy(struct tssp_pmt_es *es);

struct tssp_pmt_monitor *
tssp_pmt_monitor_attach(struct tssp *parser,
                        uint16_t program_number,
                        uint16_t pid,
                        uint8_t current_next,
                        tssp_pmt_monitor_callback callback,
                        void *userdata);
void tssp_pmt_monitor_detach(struct tssp_pmt_monitor *monitor);
void tssp_pmt_monitor_reset(struct tssp_pmt_monitor *monitor);

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* _TSSP_PMT_H_ */

